#!/sbin/openrc-run
#
# CGroups Rules Engine Daemon
#
# This is a daemon for automatically classifying processes into cgroups based
# on UID/GID.
#
opts="${opts} reload"

CGRULESENGD="/usr/sbin/cgrulesengd"
PID_FILE=${PID_FILE:-"/var/run/cgred.pid"}

depend() {
	need cgconfig
	use logger
}

start() {
	local options="${NODAEMON} ${LOG}"
	if [[ -n "${LOG_FILE}" ]]; then
		options="${options} --log-file=${LOG_FILE}"
	fi

	ebegin "Starting CGroup Rules Engine Daemon"
	start-stop-daemon --start --pidfile "${PID_FILE}" --make-pidfile \
		--background --exec "${CGRULESENGD}" -- ${options} >/dev/null
	eend $?
}

stop() {
	ebegin "Stopping CGroup Rules Engine Daemon"
	start-stop-daemon --stop --pidfile "${PID_FILE}" --exec "${CGRULESENGD}"
	eend $?
}

reload() {
	ebegin "Reloading CGroup Rules Engine Daemon"
	start-stop-daemon --stop --signal USR2 --oknodo --background \
		--pidfile "${PID_FILE}" --make-pidfile --exec "${CGRULESENGD}"
	eend $?
}
